package com.homer.iot.esptouch.tcp;

import java.util.List;

import com.homer.iot.esptouch.model.Slaver;

public class UartTCPUtil {
	static int port = 8800;

	private static TCPSocketClient getTcpSocketClient(String devHost) {
		TCPSocketClient tCPSocketClient = null;
		if (null != devHost) {
			tCPSocketClient = new TCPSocketClient(devHost, port);
			return tCPSocketClient;
		} else {
			return null;
		}
	}

	public static String getDeviceID(String devHost) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			return null;
		}
		byte[] reb = null;

		try {

			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 00 00 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x00;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				reb = tCPSocketClient.getDeviceId();
			} else {
				return null;
			}

		} catch (Exception e) {
			return null;
		} finally {
			tCPSocketClient.close();
		}
		int id = 0;

		if (null != reb)
			id = bytesToInt2(reb, 0);
		return String.valueOf(id);

	}
	public static String byteArrayToHexStr(byte[] byteArray) {
	    if (byteArray == null){
	        return null;
	    }
	    char[] hexArray = "0123456789ABCDEF".toCharArray();
	    char[] hexChars = new char[byteArray.length * 2];
	    for (int j = 0; j < byteArray.length; j++) {
	        int v = byteArray[j] & 0xFF;
	        hexChars[j * 2] = hexArray[v >>> 4];
	        hexChars[j * 2 + 1] = hexArray[v & 0x0F];
	    }
	    return new String(hexChars);
	}

	/**
	 * 将int数值转换为占四个字节的byte数组，本方法适用于(低位在前，高位在后)的顺序。 和bytesToInt（）配套使用
	 * 
	 * @param value
	 *            要转换的int值
	 * @return byte数组
	 */
	public static byte[] intToBytes(int value) {
		byte[] src = new byte[4];
		src[3] = (byte) ((value >> 24) & 0xFF);
		src[2] = (byte) ((value >> 16) & 0xFF);
		src[1] = (byte) ((value >> 8) & 0xFF);
		src[0] = (byte) (value & 0xFF);
		return src;
	}

	/**
	 * 将int数值转换为占四个字节的byte数组，本方法适用于(高位在前，低位在后)的顺序。 和bytesToInt2（）配套使用
	 */
	public static byte[] intToBytes2(int value) {
		byte[] src = new byte[4];
		src[0] = (byte) ((value >> 24) & 0xFF);
		src[1] = (byte) ((value >> 16) & 0xFF);
		src[2] = (byte) ((value >> 8) & 0xFF);
		src[3] = (byte) (value & 0xFF);
		return src;
	}

	/**
	 * byte数组中取int数值，本方法适用于(低位在前，高位在后)的顺序，和和intToBytes（）配套使用
	 * 
	 * @param src
	 *            byte数组
	 * @param offset
	 *            从数组的第offset位开始
	 * @return int数值
	 */
	public static int bytesToInt(byte[] src, int offset) {
		int value;
		value = (int) ((src[offset] & 0xFF) | ((src[offset + 1] & 0xFF) << 8)
				| ((src[offset + 2] & 0xFF) << 16) | ((src[offset + 3] & 0xFF) << 24));
		return value;
	}

	/**
	 * byte数组中取int数值，本方法适用于(低位在后，高位在前)的顺序。和intToBytes2（）配套使用
	 */
	public static int bytesToInt2(byte[] src, int offset) {
		int value;
		value = (int) (((src[offset] & 0xFF) << 24)
				| ((src[offset + 1] & 0xFF) << 16)
				| ((src[offset + 2] & 0xFF) << 8) | (src[offset + 3] & 0xFF));
		return value;
	}

	public static boolean isOnline(String devHost) {

		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			return isCon;
		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}

	}

	public static byte[] shortToByteArray(short s) {
		byte[] targets = new byte[2];
		for (int i = 0; i < 2; i++) {
			int offset = (targets.length - 1 - i) * 8;
			targets[i] = (byte) ((s >>> offset) & 0xff);
		}
		return targets;
	}

	public static boolean deleteSlaver(String devHost, short slaverID) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}
		try {

			boolean isCon = tCPSocketClient.connection();
			byte[] bb = shortToByteArray(slaverID);
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[12];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x10;
				b[8] = 0x02;
				b[9] = bb[0];
				b[10] = bb[1];
				b[11] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}

	}

	public static List<Slaver> getSlaverList(String devHost) {
		
		List<Slaver> slaverList = null;
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return null;
			}
		}

		try {

			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 0f 00 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x0f;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				slaverList = tCPSocketClient.getSlaverList();

				return slaverList;

			} else {
				return null;
			}

		} catch (Exception e) {
			return null;
		} finally {
			tCPSocketClient.close();
		}

	}

	public static boolean controlPlug(String devHost, byte action) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[11];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x01;
				b[8] = 0x01;
				b[9] = action;
				b[10] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}

	}

	public static Byte getDoorContactStatus(String devHost) {
		
		Byte ret = null;
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return null;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x02;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				ret = tCPSocketClient.getSingleValue();
				return ret;

			} else {
				return null;
			}

		} catch (Exception e) {
			return null;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static Byte getInfraredStatus(String devHost) {
		
		Byte ret = null;
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return null;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x03;
				b[8] = 0x00;
				b[10] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				ret = tCPSocketClient.getSingleValue();
				return ret;

			} else {
				return null;
			}

		} catch (Exception e) {
			return null;
		} finally {
			tCPSocketClient.close();
		}
	}

	//布防、撤防
	public static boolean controlSoundAndLightAlarm(String devHost, byte action) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[11];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x04;
				b[8] = 0x01;
				b[9] = action;
				b[10] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static boolean controlColorLamp(String devHost, byte R, byte G,
			byte B, byte whiteLight) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[14];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x05;
				b[8] = 0x04;
				b[9] = R;
				b[10] = G;
				b[11] = B;
				b[12] = whiteLight;
				b[13] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static boolean controlRelay(String devHost, byte action) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}
		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[11];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x06;
				b[8] = 0x01;
				b[9] = action;
				b[10] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static boolean controlFactoryReset(String devHost) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = (byte) 0xfe;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}
	}

	// 设置警戒模式，0：非警戒模式 1：警戒模式
	public static boolean setAlarmMode(String devHost, byte action) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}
		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[11];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x21;
				b[8] = 0x01;
				b[9] = action;
				b[10] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static boolean allowJoinNewDevice(String devHost, byte action) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[11];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x12;
				b[8] = 0x01;
				b[9] = action;
				b[10] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static boolean deviceAction(String devHost, byte[] value) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[13];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x11;
				b[8] = 0x03;
				b[9] = value[0];
				b[10] = value[1];
				b[11] = value[2];
				b[12] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static Byte getRSSI(String devHost) {
		
		Byte ret = null;		
		
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return ret;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x0b;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				ret = tCPSocketClient.getSingleValue();
				return ret;

			} else {
				return ret;
			}

		} catch (Exception e) {
			return ret;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static boolean saveParam(String devHost) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = (byte) 0xfa;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static Byte getTemperature(String devHost) {
		
		Byte ret = null;
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return ret;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = (byte) 0x07;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				ret = tCPSocketClient.getSingleValue();
				return ret;

			} else {
				return ret;
			}

		} catch (Exception e) {
			return ret;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static Byte getHumidity(String devHost) {
		
		Byte ret = null;
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return ret;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = (byte) 0x08;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				ret = tCPSocketClient.getSingleValue();
				return ret;

			} else {
				return ret;
			}

		} catch (Exception e) {
			return ret;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static Byte getSmokeDetection(String devHost) {
		
		Byte ret = null;
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return ret;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = (byte) 0x09;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				ret = tCPSocketClient.getSingleValue();
				return ret;

			} else {
				return ret;
			}

		} catch (Exception e) {
			return ret;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static byte[] getVolt(String devHost) {
		
		byte[] ret = null;
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return ret;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[10];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = (byte) 0x0a;
				b[8] = 0x00;
				b[9] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				ret = tCPSocketClient.getDoubleValue();
				return ret;

			} else {
				return ret;
			}

		} catch (Exception e) {
			return ret;
		} finally {
			tCPSocketClient.close();
		}
	}

	public static boolean playSound(String devHost, byte[] action) {
		TCPSocketClient tCPSocketClient = getTcpSocketClient(devHost);
		if (null == tCPSocketClient) {
			tCPSocketClient = getTcpSocketClient(devHost);
			if (null == tCPSocketClient) {
				return false;
			}
		}

		try {
			boolean isCon = tCPSocketClient.connection();
			if (isCon) {
				// 5A 00 00 00 00 00 00 10 02 46 76 A5
				byte[] b = new byte[12];
				b[0] = 0x5A;
				b[1] = 0x00;
				b[2] = 0x00;
				b[3] = 0x00;
				b[4] = 0x00;
				b[5] = 0x00;
				b[6] = 0x00;
				b[7] = 0x16;
				b[8] = 0x02;
				b[9] = action[0];
				b[10] = action[1];
				b[11] = (byte) 0xA5;
				tCPSocketClient.sendData(b);
				return true;

			} else {
				return false;
			}

		} catch (Exception e) {
			return false;
		} finally {
			tCPSocketClient.close();
		}
	}

}
